<template>
	<view class="order-index">
		<view class="order-list">
			<view class="u-flex" style="padding: 20rpx 0;justify-content: flex-end;">
				<view class="u-flex st-item" @click="processon">
					<view class="st-l">添加记录</view>
				</view>
			</view>
			
			<view class="order-item" v-for="(item,key) in orderList" :key="key">
				<view class="order-item__info flex">
					<view class="title">跟进时间</view>
					<view class="value">{{ item.ontime_display }}</view>
				</view>
				<view class="order-item__info flex">
					<view class="title">跟进内容</view>
					<view class="value">{{ item.content }}</view>
				</view>
				
			</view>
		</view>
		
		<u-loadmore :status="loadStatus" fontSize="32" :iconSize="32" line />
		
		<!-- 跟进 -->
		<u-modal :show="cusProcesson" title="客户跟进" showCancelButton confirmColor="#ff5a5f" @confirm="submitProcesson()" @cancel="cusProcesson=false">
			<view class="slot-content">
				<u-form labelPosition="left" :model="processonForm" labelWidth="140" ref="uForm">
					<u-form-item label="跟进内容" prop="processonForm.content" borderBottom>
						<view class="text-area-box">
							<u-textarea v-model="processonForm.content" placeholder="请填写跟进内容" :height="200" :maxlength="300" autoHeight count></u-textarea>
						</view>
					</u-form-item>
				</u-form>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import { getCustomerProcessons,cusProcessonSave } from '@/api/api.js'
	export default {
		data() {
			return {
				loadStatus: 'loadmore',
				filter: {
					uid: 0,
					page: 1,
					limit: 20
				},
				orderList: [],
				cusProcesson: false,
				processonForm: {
					uid: 0,
					content: ''
				},
			}
		},
		methods:{
			searchCustomer() {
				this.initPage()
				this.getProcessonList()
			}
			,getProcessonList() {
				if ( this.loadStatus == 'nomore' ) {
					return console.log('nomore')
				}
				
				uni.showLoading({
					title: '加载中'
				})
				this.loadStatus = 'loading'
				getCustomerProcessons(uni.$lv.object.queryParams(this.filter)).then(res => {
					uni.hideLoading()
					let _result = res.data || []
					if ( !_result.length ) {
						return this.loadStatus = 'nomore'
					}
					this.orderList = uni.$lv.array.union(this.orderList , _result)
					this.loadStatus = 'loadmore'
				})
			}
			,initPage() {
				this.loadStatus = 'loadmore'
				this.filter.page = 1
				this.orderList = []
			}
			// 客户跟进
			,processon() {
				this.processonForm.uid = this.filter.uid
				this.processonForm.content = ''
				this.cusProcesson = true
			}
			// 提交客户跟进内容
			,submitProcesson() {
				if ( !this.processonForm.content ) {
					return uni.showToast({
						title: '内容不能为空',
						icon: 'none'
					})
				}
				
				uni.showLoading({
					title: '提交中'
				})
				cusProcessonSave(this.processonForm).then(res => {
					uni.showToast({
						title: '保存成功'
					})
					this.cusProcesson = false
					
					this.initPage()
					this.getProcessonList()
				})
			}
		},
		onLoad(options) {
			// 如果参数中有customerUid说明是普通销售经理
			this.filter.uid = options.customerUid || 0
		},
		mounted() {
			this.getProcessonList()
		},
		/**
		 * 下拉刷新回调函数
		 */
		onPullDownRefresh() {
			this.initPage()
			this.getProcessonList()
			uni.stopPullDownRefresh()
		},
		/**
		 * 上拉加载回调函数
		 */
		onReachBottom() {
			this.filter.page++
			this.getProcessonList()
		},
		watch: {
			
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: $uni-bg-color-grey;
	}
	.st-item {
		.st-l {
			font-size: 26rpx;
			color: #fff;
			background-color: $uni-primary-main;
			padding: 4rpx 10rpx;
			border-radius: 10rpx;
		}
		
	}
	.order-index {
		background-color: $uni-bg-color-grey;
		.text-area-box {
			width: 360rpx;
		}
		padding-bottom: 30rpx;
		.order-statistic {
			background-color: #FFFFFF;
			padding: 30rpx;
			justify-content: space-between;
			flex-wrap: wrap;
			
			&__item {
				flex-direction: column;
				align-items: center;
				width: 33%;
				margin-bottom: 20rpx;
				.key {
					font-size: 26rpx;
					color: #909399;
				}
				.value {
					justify-content: center;
					align-items: center;
					font-weight: bold;
					color: $uni-color-error;
					font-size: 42rpx;
					margin-bottom: 0rpx;
				}
			}
		}
		.search-wrap {
			background-color: #FFFFFF;
			padding: 30rpx;
			.search-item {
				@include flex;
				align-items: center;
				.label {
					width: 140rpx;
					color: $u-main-color;
					font-size: 26rpx;
				}
				.input-box {
					flex: 1;
					.amt-input {
						flex: 1;
					}
					.sep {
						font-size: 26rpx;
						color: #999;
						width: 100rpx;
						text-align: center;
					}
				}
				margin-bottom: 20rpx;
			}
			.search-footer {
				margin-top: 30rpx;
				justify-content: end;
				.search {
					width: 160rpx;
				}
			}
		}
		.order-list {
			padding: 30rpx;
			.order-item {
				padding: 30rpx;
				background-color: #FFFFFF;
				border-radius: 20rpx;
				&__info {
					font-size: 28rpx;
					.title{
						margin-right: 20rpx;
						color: #909399;
						width: 130rpx;
					}
					.value {
						color: $u-main-color;
						flex: 1;
						color: #666;
					}
				}
				&__info:not(:last-child){margin-bottom: 20rpx;}
			}
			.order-item:not(:last-child){margin-bottom: 40rpx;}
		}
	}
</style>
